package com.itheima03.day12Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Scanner;

/**
 * @author 刘全
 * @date 2021/8/3
 */
public class Test2 {
    public static void main(String[] args) throws IOException {
        /**
         * 2. 已知文件中存在包含重复内容的字符串，将文件中的数据去重:
         *     原文：aabbccddeefffffggg
         *     去重后：abcdefg
         */
        FileInputStream fis = new FileInputStream("D:\\c.txt");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要新建的文件名");
        String s = sc.nextLine();
        File file = new File("D:\\",s+".txt");
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        LinkedHashSet<Integer> set = new LinkedHashSet<>();
        int b;
        while ((b = fis.read()) != -1) {
            set.add(b);
        }
        fis.close();
        System.out.println(set);
        for (Integer i : set) {
            fos.write(i);
        }
        fos.close();
    }
}
